/* =================================
   LOADER                     
=================================== */
// makes sure the whole site is loaded
jQuery(window).load(function() {
        // will first fade out the loading animation
	jQuery(".status").fadeOut();
        // will fade out the whole DIV that covers the website.
	jQuery(".preloader").delay(1000).fadeOut("slow");
})

/* Smooth Scroll */
$(function() {  
  $('a[href*=#]:not([href=#]):not([href=#myCarousel])').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {

	  var target = $(this.hash);
	  target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
	  if (target.length) {
		$('html,body').animate({
		  scrollTop: target.offset().top
		}, 1000);
		return false;
	  }
	}		
  });
});

/* NAVIGATION VISIBLE ON SCROLL */

$(document).ready(function () {
    socials();	
});

$(window).scroll(function () {
    socials();	
});

if (matchMedia('(min-width: 992px), (max-width: 767px)').matches) {
  function socials() {
        var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
        if (top > 1000){
			$('.socials').stop(0,1).fadeIn(200);
		}
        else $('.socials').stop(0,1).fadeOut(300);
    }
}

/* =================================
===  SMOOTH SCROLL             ====
=================================== */
var scrollAnimationTime = 1200,
    scrollAnimation = 'easeInOutExpo';
$('a.scrollto').bind('click.smoothscroll', function (event) {
    event.preventDefault();
    var target = this.hash;
    $('html, body').stop().animate({
        'scrollTop': $(target).offset().top
    }, scrollAnimationTime, scrollAnimation, function () {
        window.location.hash = target;
    });
});


/* =================================
===  WOW ANIMATION             ====
=================================== */
wow = new WOW(
  {
    mobile: false
  });
wow.init();


/* =================================
===  OWL CROUSEL               ====
=================================== */
$(document).ready(function () {
	 if($('#submit').length){
      $('#submit').click(checkContact)
   }
	var owl = $('#feedbacks');
	owl.owlCarousel({		
		nav: true,
		loop: true,
		items: 1,
		navText: ["",""]
		
	});
	 


});

function checkMail(sEmail) {
    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (filter.test(sEmail)) {
        return true;
    }
    else {
        return false;
    }
}

function checkContact(){
  if($('#name').length && $('#name').val() == ''){
    alert('Please enter your name')
    $('#name').focus()
  }else if($('#email').length && $('#email').val() == ''){
      alert('Please enter your email')
      $('#email').focus()
  }else if(checkMail($('#email').val()) == false) {
      alert('Please check your email.')
      $('#email').focus()
  }else if($('#subject').length && $('#subject').val() == ''){
    alert('Please enter your subject')
    $('#subject').focus()
  }else if($('#message').length && $('#message').val() == ''){
    alert('Please enter your message')
    $('#message').focus()
  }else{
    var name = $('#name').val()
    var email = $('#email').val()
    var subject= $('#subject').val()
    var message = $('#message').val()
    $.ajax({
      url: 'site/contact',
      type:'post',
      async: true,
      data:{name:name, email:email, subject:subject, message: message},
      success: function(data){
        if(data){
          alert('Your information has been sent to us, we will contact you as soon as possible. Thank you!')
          $('#name').val('');
          $('#email').val('')
          $('#subject').val('')
          $('#message').val('')
        }else{
          alert('Faild');
        }
      }
    })
  }
}
/* =================================
===  IE10 ON WINDOWS 8 FIX      ====
=================================== */
if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
  var msViewportStyle = document.createElement('style')
  msViewportStyle.appendChild(
    document.createTextNode(
      '@-ms-viewport{width:auto!important}'
    )
  )
  document.querySelector('head').appendChild(msViewportStyle)
}